@ibiz-template-plugin/ibiz-file-previewer 0.0.14 → 0.0.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.es.js CHANGED
@@ -1189,6 +1189,39 @@ const throttle = (func, wait) => {
1189
1189
  }
1190
1190
  };
1191
1191
  };
1192
+ const fallbackCopyTextToClipboard = (text) => {
1193
+ const textArea = document.createElement("textarea");
1194
+ textArea.value = text;
1195
+ textArea.style.position = "fixed";
1196
+ textArea.style.left = "-999999px";
1197
+ textArea.style.top = "-999999px";
1198
+ document.body.appendChild(textArea);
1199
+ textArea.focus();
1200
+ textArea.select();
1201
+ try {
1202
+ const successful = document.execCommand("copy");
1203
+ document.body.removeChild(textArea);
1204
+ if (successful) {
1205
+ return true;
1206
+ }
1207
+ return false;
1208
+ } catch (err) {
1209
+ document.body.removeChild(textArea);
1210
+ return false;
1211
+ }
1212
+ };
1213
+ const copyTextToClipboard = async (text) => {
1214
+ if (navigator.clipboard && window.isSecureContext) {
1215
+ try {
1216
+ await navigator.clipboard.writeText(text);
1217
+ return true;
1218
+ } catch (err) {
1219
+ return fallbackCopyTextToClipboard(text);
1220
+ }
1221
+ } else {
1222
+ return fallbackCopyTextToClipboard(text);
1223
+ }
1224
+ };
1192
1225
  var f = 0;
1193
1226
  function u(e2, t2, n2, o2, i2, u2) {
1194
1227
  t2 || (t2 = {});
@@ -18284,18 +18317,6 @@ const FilePreviewText = (props) => {
18284
18317
  }
18285
18318
  ) });
18286
18319
  };
18287
- const FilePreviewUnkown = (props) => {
18288
- const c2 = props.controller;
18289
- const fileType = c2.filePreviewShell.getState().fileType;
18290
- y$1(() => {
18291
- props.onInitialization();
18292
- }, []);
18293
- return /* @__PURE__ */ u("div", { className: "file-preview-unkown ".concat(c2.state.value.theme), children: /* @__PURE__ */ u("div", { children: [
18294
- "暂未支持",
18295
- fileType,
18296
- "类型预览"
18297
- ] }) });
18298
- };
18299
18320
  const Loading = ({ size = 24 }) => {
18300
18321
  return /* @__PURE__ */ u("div", { className: "loading-mask", children: /* @__PURE__ */ u("div", { className: "loading-spinner", children: /* @__PURE__ */ u(LoaddingSvg, { size }) }) });
18301
18322
  };
@@ -19031,7 +19052,7 @@ const FilePreviewShell = (props) => {
19031
19052
  ] })
19032
19053
  ] }),
19033
19054
  showDownloadMenu.value && /* @__PURE__ */ u("div", { className: "download-options", children: [
19034
- /* @__PURE__ */ u(
19055
+ state.value.fileContent === "" && /* @__PURE__ */ u(
19035
19056
  "button",
19036
19057
  {
19037
19058
  className: "download-option",
@@ -19041,7 +19062,7 @@ const FilePreviewShell = (props) => {
19041
19062
  children: "下载原文件"
19042
19063
  }
19043
19064
  ),
19044
- state.value.engineType !== EngineType.PDF && state.value.engineType !== EngineType.UNKNOWN && /* @__PURE__ */ u(
19065
+ state.value.engineType !== EngineType.PDF && /* @__PURE__ */ u(
19045
19066
  "button",
19046
19067
  {
19047
19068
  className: "download-option",
@@ -20023,8 +20044,11 @@ class FilePreviewTextController extends FilePreviewItemController {
20023
20044
  */
20024
20045
  async getContent() {
20025
20046
  const options = this.filePreviewShell.getOptions();
20026
- const { fileId, fileType, fileCat } = this.filePreviewShell.getState();
20047
+ const { fileId, fileType, fileCat, fileContent } = this.filePreviewShell.getState();
20027
20048
  try {
20049
+ if (fileContent) {
20050
+ return fileContent;
20051
+ }
20028
20052
  const content = await options.getContent(fileId, fileType, fileCat);
20029
20053
  return content || "";
20030
20054
  } catch (error2) {
@@ -20128,9 +20152,14 @@ class FilePreviewItemDispatcher {
20128
20152
  );
20129
20153
  this.registerItem(
20130
20154
  EngineType.UNKNOWN,
20131
- FilePreviewUnkown,
20155
+ // 未识别类型统一识别为md格式
20156
+ // FilePreviewUnkown as PreviewItemComponent,
20157
+ // (filePreviewShell: IFilePreviewShellController) => {
20158
+ // return new FilePreviewItemController(filePreviewShell);
20159
+ // },
20160
+ FilePreviewMD,
20132
20161
  (filePreviewShell) => {
20133
- return new FilePreviewItemController(filePreviewShell);
20162
+ return new FilePreviewMDController(filePreviewShell);
20134
20163
  }
20135
20164
  );
20136
20165
  }
@@ -20173,6 +20202,7 @@ class FilePreviewShellController {
20173
20202
  fileName: "",
20174
20203
  fileId: "",
20175
20204
  fileCat: "",
20205
+ fileContent: "",
20176
20206
  theme: "dark",
20177
20207
  isLoading: false,
20178
20208
  isCreated: false,
@@ -20201,7 +20231,11 @@ class FilePreviewShellController {
20201
20231
  let fileId = "";
20202
20232
  let fileName = "";
20203
20233
  let fileCat = "";
20204
- if (data.url) {
20234
+ let fileContent = "";
20235
+ if (data.content) {
20236
+ fileName = data.name || "";
20237
+ fileContent = data.content;
20238
+ } else if (data.url) {
20205
20239
  const result = await this.options.upLoadFileToOss(data.url);
20206
20240
  if (result) {
20207
20241
  const { id, name, cat } = result;
@@ -20215,7 +20249,7 @@ class FilePreviewShellController {
20215
20249
  if (data.id) fileId = data.id;
20216
20250
  }
20217
20251
  const fileType = fileNameToFileType(fileName);
20218
- this.updateState({ fileId, fileName, fileCat, fileType });
20252
+ this.updateState({ fileId, fileName, fileCat, fileType, fileContent });
20219
20253
  await this.parseEngineType();
20220
20254
  }
20221
20255
  /**
@@ -20314,11 +20348,18 @@ class FilePreviewShellController {
20314
20348
  */
20315
20349
  async copyTextContent(_event) {
20316
20350
  if (!this.options.getContent) return;
20317
- await navigator.clipboard.writeText("");
20318
- const { fileId, fileType, fileCat } = this.state.value;
20319
- const content = await this.options.getContent(fileId, fileType, fileCat);
20351
+ await copyTextToClipboard("");
20352
+ const { fileId, fileType, fileCat, fileContent } = this.state.value;
20353
+ let content = fileContent;
20354
+ if (content === "") {
20355
+ content = await this.options.getContent(
20356
+ fileId,
20357
+ fileType,
20358
+ fileCat
20359
+ );
20360
+ }
20320
20361
  if (content) {
20321
- await navigator.clipboard.writeText(content);
20362
+ await copyTextToClipboard(content);
20322
20363
  }
20323
20364
  if (this.options.actionSuccessCallBack) {
20324
20365
  await this.options.actionSuccessCallBack(ActionType.COPYTEXTCONTENT);